package db_meta

import (
	"engine/db"
	"gitee.com/ameise84/e3utils/str_conv"
	jsoniter "github.com/json-iterator/go"
	"servers/models/define"
	"servers/models/protos/google/pb/rpc_protos"
)

func init() {
	db.RegisterTableMetaFactory(AcBusinessFactory)
}

func AcBusinessFactory() db.TableMeta {
	return &AcBusiness{}
}

type AcBusiness struct {
	BusinessID  define.BusinessIDType `json:"id" form:"id" gorm:"primarykey;column:id"`                 // 平台ID
	ScoreType   define.ScoreType      `json:"score_type" form:"score_type" gorm:"column:score_type"`    // 积分类型
	BagType     define.BagType        `json:"bag_type" form:"bag_type" gorm:"column:bag_type"`          // 钱包类型
	IsTest      bool                  `json:"is_test" form:"is_test" gorm:"column:is_test"`             // 是否测试
	ScoreLimit  define.GameScore      `json:"score_limit" form:"score_limit" gorm:"column:score_limit"` // 带出分数限制
	GameGroupID int                   `json:"game_group_id" form:"game_group_id" gorm:"column:game_group_id"`
	LogoGroupID int                   `json:"logo_group_id" form:"logo_group_id" gorm:"column:logo_group_id"`
	Mark        uint64                `json:"mark" form:"mark" gorm:"column:mark"`
}

func (v *AcBusiness) Init() {
	v.BusinessID = 0
	v.ScoreType = 0
	v.BagType = 0
	v.IsTest = true
	v.ScoreLimit = 0
}

func (v *AcBusiness) BaseTableName() string {
	return v.TableName()
}

func (v *AcBusiness) TableName() string {
	return "ac_business"
}

func (v *AcBusiness) ID() string {
	return str_conv.ToString(v.BusinessID)
}

func (v *AcBusiness) MarshalBinary() (data []byte, err error) {
	return jsoniter.Marshal(v)
}

func (v *AcBusiness) UnmarshalBinary(data []byte) error {
	return jsoniter.Unmarshal(data, v)
}

func (v *AcBusiness) ToPBMeta(meta *rpc_protos.BusinessMeta) {
	meta.ID = v.BusinessID
	meta.ScoreType = v.ScoreType
	meta.BagType = v.BagType
	meta.IsTest = v.IsTest
	meta.ScoreLimit = v.ScoreLimit
}

func (v *AcBusiness) FromPBMeta(meta *rpc_protos.BusinessMeta) {
	v.BusinessID = meta.ID
	v.ScoreType = meta.ScoreType
	v.BagType = meta.BagType
	v.IsTest = meta.IsTest
	v.ScoreLimit = meta.ScoreLimit
}
